sap.ui.define([
    "sap/ui/core/mvc/Controller",
    'sap/ui/layout/SplitterLayoutData',
    'sap/m/Button',
    'sap/ui/core/library',
    'sap/m/MessageToast'
],
    /**
     * @param {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller,SplitterLayoutData,Button,coreLibrary,MessageToast) {
        "use strict";

        return Controller.extend("c060.controller.Main", {
            onInit: function () {
                this.oSplitter = this.byId("mainSplitter");
            },
            btnAddContentArea: function () {
                var oLayoutData = new SplitterLayoutData({
                    resizable: true,
                    size: Math.random() > 0.5 ? "auto" : 50 + Math.floor(Math.random() * 300) + "px",
                    maxSize: Math.random() > 0.5 ? "0" : Math.floor(Math.random() * 100) + "px"
                });
    
                var oContent = new Button({
                    width: "100%",
                    height: "100%",
                    text: "Content!",
                    layoutData: oLayoutData
                });

                this.oSplitter.addContentArea(oContent);
            },
            btnRemoveContentArea: function () {
                
    
                var oLastContentArea = this.oSplitter.getContentAreas().pop();
                this.oSplitter.removeContentArea(oLastContentArea);
                oLastContentArea.destroy();
            },
            btnSetResizable:function(){
                var oContentArea = this.oSplitter.getContentAreas()[0];
                var oLayoutData = oContentArea.getLayoutData();

                oLayoutData.setResizable(false)
            },
            btnChangeOrientation: function () {
                var Orientation = coreLibrary.Orientation;
                var sOr = this.oSplitter.getOrientation();
                this.oSplitter.setOrientation(
                    sOr === Orientation.Vertical
                        ? Orientation.Horizontal
                        : Orientation.Vertical
                );
            },
            onRootContainerResize: function (oEvent) {
                var aOldSizes = oEvent.getParameter("oldSizes"),
                    aNewSizes = oEvent.getParameter("newSizes"),
                    sMessage =  "Root container is resized.";
    
                if (aOldSizes && aOldSizes.length) {
                    sMessage += "\nOld panes sizes = [" + aOldSizes + "]";
                }
    
                sMessage += "\nNew panes sizes = [" + aNewSizes + "]";
    
                MessageToast.show(sMessage);
            },
    
            onInnerContainerResize: function (oEvent) {
                var aOldSizes = oEvent.getParameter("oldSizes"),
                    aNewSizes = oEvent.getParameter("newSizes"),
                    sMessage =  "Inner container is resized.";
    
                if (aOldSizes && aOldSizes.length) {
                    sMessage += "\nOld panes sizes = [" + aOldSizes + "]";
                }
    
                sMessage += "\nNew panes sizes = [" + aNewSizes + "]";
    
                MessageToast.show(sMessage);
            }

        });
    });
